home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / Rxil.lha / Rxil / src / cancel.c next >
Encoding:
C/C++ Source or Header  |  1989-12-30  |  7.4 KB  |  427 lines

  1. /* cancel.c */
  2.  
  3. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  4.  *        All Rights Reserved
  5.  */
  6.  
  7.  
  8.  
  9. #include "rxil.h"
  10.  
  11. #include <exec/memory.h>
  12.  
  13. #include <proto/intuition.h>
  14.  
  15.  
  16.  
  17.  
  18. #define REQ_LEFT          3
  19. #define REQ_TOP             11
  20. #define REQ_WIDTH        180
  21. #define REQ_HEIGHT         50
  22.  
  23. #define GADGET_LEFT        20
  24. #define GADGET_TOP        8
  25. #define GADGET_WIDTH    REQ_WIDTH - 40
  26. #define GADGET_HEIGHT    REQ_HEIGHT - 16
  27.  
  28.  
  29.  
  30. static struct IntuiText itext[2] = {
  31.     { 1, 0, JAM1, 12, 10, NULL, (UBYTE *)"Click Here To", &itext[1] },
  32.     { 1, 0, JAM1, 16, 20, NULL, (UBYTE *)"Cancel Macro", NULL },
  33. };
  34.  
  35.  
  36.  
  37. static SHORT vectors[4][10] = {
  38.     {
  39.     0, 0,   REQ_WIDTH-1, 0,   REQ_WIDTH-1, REQ_HEIGHT-1,
  40.     0, REQ_HEIGHT-1,   0, 0
  41.     },
  42.     {
  43.     0, 0,   REQ_WIDTH-9, 0,   REQ_WIDTH-9, REQ_HEIGHT-7,
  44.     0, REQ_HEIGHT-7,   0, 0
  45.     },
  46.     {
  47.     0, 0,   GADGET_WIDTH-1, 0,   GADGET_WIDTH-1, GADGET_HEIGHT-1,
  48.     0, GADGET_HEIGHT-1,   0, 0
  49.     },
  50.     {
  51.     0, 0,   GADGET_WIDTH-9, 0,   GADGET_WIDTH-9, GADGET_HEIGHT-7,
  52.     0, GADGET_HEIGHT-7,   0, 0
  53.     }
  54. };
  55.  
  56.  
  57. static struct Border border[4] = {
  58.     {
  59.     0, 0, 1, 0, JAM1, 5, (SHORT *)&vectors[0][0], &border[1]
  60.     },
  61.     {
  62.     4, 3, 1, 0, JAM1, 5, (SHORT *)&vectors[1][0], NULL
  63.     },
  64.     {
  65.     0, 0, 3, 0, JAM1, 5, (SHORT *)&vectors[2][0], &border[3]
  66.     },
  67.     {
  68.     4, 3, 3, 0, JAM1, 5, (SHORT *)&vectors[3][0], NULL
  69.     }
  70. };
  71.  
  72.  
  73. static struct Gadget gadget = {
  74.     NULL,                    /* NextGadget */
  75.     GADGET_LEFT, GADGET_TOP,    /* LeftEdge, TopEdge */
  76.     GADGET_WIDTH,            /* Width */
  77.     GADGET_HEIGHT,            /* Height */
  78.     GADGHCOMP,                /* Flags */
  79. /*    ENDGADGET | */
  80.     RELVERIFY,                /* Activation */
  81.     REQGADGET |
  82.     BOOLGADGET,                /* GadgetType */
  83.     (APTR)&border[2],        /* GadgetRender */
  84.     NULL,                    /* SelectRender */
  85.     &itext[0],                /* GadgetText */
  86.     NULL,                    /* MutualExclude */
  87.     NULL,                    /* SpecialInfo */
  88.     0,                        /* GadgetID */
  89.     NULL                    /* UserData */
  90. };
  91.  
  92.  
  93. static struct NewWindow newwin_template = {
  94.     20, 14,                        /* LeftEdge, TopEdge */
  95.     REQ_WIDTH + 6,                /* Width */
  96.     REQ_HEIGHT + 14,            /* Height */
  97.     0, 1,                        /* DetailPen, BlockPen */
  98.     GADGETUP,                    /* IDCMP Flags */
  99.     WINDOWDEPTH |
  100.     WINDOWDRAG |
  101.     SMART_REFRESH |
  102.     NOCAREREFRESH,                /* Flags */
  103.     NULL,                        /* FirstGadget */
  104.     NULL,                        /* CheckMark */
  105.     (UBYTE *)"ARexx Macro",        /* Title */
  106.     NULL,                        /* Screen */
  107.     NULL,                        /* BitMap */
  108.     0, 0,                        /* MinWidth, MinHeight */
  109.     0, 0,                        /* MaxWidth, MaxHeight */
  110.     WBENCHSCREEN                /* Type */
  111. };
  112.  
  113.  
  114. static struct Requester req_template = {
  115.     NULL,                    /* OlderRequester */
  116.     REQ_LEFT, REQ_TOP,        /* LeftEdge, TopEdge */
  117.     REQ_WIDTH, REQ_HEIGHT,    /* Width, Height */
  118.     0, 0,                    /* RelLeft, RelTop */
  119.     &gadget,                /* ReqGadget */
  120.     &border[0],                /* ReqBorder */
  121.     NULL,                    /* ReqText */
  122.     NULL,                    /* Flags */
  123.     2,                        /* BackFill */
  124.     NULL,                    /* ReqLayer */
  125.     {NULL},                    /* Pad */
  126.     {NULL},                    /* BitMap */
  127.     NULL,                    /* RWindow */
  128.     {NULL},                    /* Pad */
  129. };
  130.  
  131.  
  132.  
  133.  
  134. /* NAME
  135.  *        RxilCancel
  136.  *
  137.  * SYNOPSIS
  138.  *        RxilCancel();
  139.  *
  140.  * FUNCTION
  141.  *        Sets the abort condition for ARexx macros.  This is accomplished
  142.  *        by setting the Abort flag in the RxilDef structure.
  143.  *        All ARexx messages received at the ARexx ports while this flag
  144.  *        is set will be returned with an error code.
  145.  *        Unless the RXIL_NO_CLEAR_ABORT flag is set, the Abort flag will
  146.  *        be cleared automaticly when the last ARexx program launched by
  147.  *        this application has finished.
  148.  *
  149.  *
  150.  * INPUTS
  151.  *        None
  152.  *
  153.  * RESULT
  154.  *        None
  155.  *
  156.  * SIDES
  157.  *
  158.  * HISTORY
  159.  *        01-Aug-89    Creation.
  160.  *        18-Nov-89    Fixed bug whereby cancel requesters would post
  161.  *                    more than once.
  162.  *
  163.  * BUGS
  164.  *
  165.  * SEE ALSO
  166.  *
  167.  */
  168.  
  169. void RxilCancel( void )
  170. {
  171.     /* Make call "safe" even if RxilInit() failed */
  172.     if( global_rdef != NULL )
  173.     {
  174.         global_rdef->Abort = TRUE;
  175.     }
  176. }
  177.  
  178.  
  179.  
  180. /* NAME
  181.  *        RxilCheckCancel
  182.  *
  183.  * SYNOPSIS
  184.  *        flag = RxilCheckCancel();
  185.  *
  186.  *        BOOL flag;
  187.  *
  188.  * FUNCTION
  189.  *        Checks to see if the button on the cancel macro requester has
  190.  *        been clicked by the user or not.
  191.  *        This will return FALSE if the cancel requester is not posted. 
  192.  *
  193.  * INPUTS
  194.  *        None
  195.  *
  196.  * RESULT
  197.  *        A boolean TRUE if the cancel requester has been clicked.
  198.  *
  199.  * SIDES
  200.  *
  201.  * HISTORY
  202.  *        01-Aug-89    Creation.
  203.  *
  204.  * BUGS
  205.  *
  206.  * SEE ALSO
  207.  *        RxilPostCancel(), RxilEndCancel()
  208.  */
  209.  
  210. BOOL RxilCheckCancel( void )
  211. {
  212.     struct IntuiMessage *message;
  213.     ULONG class;
  214.     struct RxilCancelReq *creq;
  215.  
  216.  
  217.     if( global_rdef == NULL )
  218.     {
  219.         return( FALSE );
  220.     }
  221.  
  222.     creq = global_rdef->CReq;
  223.  
  224.     if( creq == NULL )
  225.     {
  226.         return( FALSE );
  227.     }
  228.  
  229.  
  230.     /* See if user clicked the CANCEL gadget */
  231.  
  232.     message = (struct IntuiMessage *)GetMsg( creq->win->UserPort );
  233.     if( message )
  234.     {
  235.         class = message->Class;
  236.  
  237.         ReplyMsg( (struct Message *)message );
  238.  
  239.         if( class == GADGETUP )
  240.         {
  241.             RxilEndCancel();
  242.             return( TRUE );
  243.         }
  244.     }
  245.  
  246.     return( FALSE );
  247. }
  248.  
  249.  
  250.  
  251. /* NAME
  252.  *        RxilPostCancel
  253.  *
  254.  * SYNOPSIS
  255.  *        RxilPostCancel();
  256.  *
  257.  * FUNCTION
  258.  *        This will post a cancel requester to allow the user to halt
  259.  *        macro execution by clicking a button on the requester.
  260.  *        The CancelWindow member of the RxilDef structure controls
  261.  *        where the requester is posted.
  262.  *        In the current version, the cancel requester always opens it's
  263.  *        own window on the same screen as the Window whose pointer is
  264.  *        in CancelWindow.  If CancelWindow is NULL, the window will open
  265.  *        on the WorkBench.
  266.  *
  267.  * INPUTS
  268.  *        None
  269.  *
  270.  * RESULT
  271.  *        None
  272.  *
  273.  * SIDES
  274.  *
  275.  * HISTORY
  276.  *        01-Aug-89    Creation.
  277.  *
  278.  * BUGS
  279.  *
  280.  * SEE ALSO
  281.  *        RxilCheckCancel(), RxilEndCancel()
  282.  */
  283.  
  284. void RxilPostCancel( void )
  285. {
  286.     struct RxilCancelReq *creq;
  287.     struct NewWindow *newwin;
  288.  
  289.  
  290.     if( global_rdef == NULL )
  291.     {
  292.         return;
  293.     }
  294.  
  295.     /* On the off-chance that Intuition is not open... */
  296.     if(  IntuitionBase == NULL  )
  297.     {
  298.         return;
  299.     }
  300.  
  301.     if( global_rdef->CReq != NULL )
  302.     {
  303.         /* Already a cancel requester posted.  Don't post another one!
  304.          */
  305.         return;
  306.     }
  307.  
  308.  
  309.     creq = AllocMem( sizeof(struct RxilCancelReq),
  310.         MEMF_PUBLIC | MEMF_CLEAR );
  311.     if( creq == NULL )
  312.     {
  313.         return;
  314.     }
  315.  
  316.  
  317.     /* Open our window */
  318.  
  319.     newwin = AllocMem( sizeof(struct NewWindow),
  320.         MEMF_PUBLIC | MEMF_CLEAR );
  321.     if( newwin == NULL )
  322.     {
  323.         FreeMem( creq, sizeof(struct RxilCancelReq) );
  324.         return;
  325.     }
  326.  
  327.     CopyMem( (char *)&newwin_template, (char *)newwin,
  328.         sizeof(struct NewWindow) );
  329.  
  330.     if( global_rdef->CancelWindow != NULL )
  331.     {
  332.         /* Client has set a window for us to (currently) derive the
  333.          * screen from.
  334.          */
  335.         if( global_rdef->CancelWindow->WScreen != NULL )
  336.         {
  337.             /* And it's not the WorkBench (which is our default), so
  338.              * set things up to open our window on that screen.
  339.              */
  340.             newwin->Screen = global_rdef->CancelWindow->WScreen;
  341.             newwin->Type = CUSTOMSCREEN;
  342.         }
  343.     }
  344.  
  345.     creq->win = OpenWindow( newwin );
  346.  
  347.     FreeMem( newwin, sizeof(struct NewWindow) );
  348.  
  349.     if( creq->win == NULL )
  350.     {
  351.         FreeMem( creq, sizeof(struct RxilCancelReq) );
  352.         return;
  353.     }
  354.  
  355.  
  356.     CopyMem( (char *)&req_template, (char *)&creq->req,
  357.         sizeof(struct Requester) );
  358.  
  359.     if(  Request( &creq->req, creq->win ) == FALSE  )
  360.     {
  361.         /* Unable to post the requester for some reason */
  362.         CloseWindow( creq->win );
  363.         FreeMem( creq, sizeof(struct RxilCancelReq) );
  364.         return;
  365.     }
  366.  
  367.  
  368.     global_rdef->CReq = creq;
  369.  
  370.     return;
  371. }
  372.  
  373.  
  374.  
  375. /* NAME
  376.  *        RxilEndCancel
  377.  *
  378.  * SYNOPSIS
  379.  *        RxilEndCancel();
  380.  *
  381.  * FUNCTION
  382.  *        Removes the cancel requester.
  383.  *
  384.  * INPUTS
  385.  *        None
  386.  *
  387.  * RESULT
  388.  *        None
  389.  *
  390.  * SIDES
  391.  *
  392.  * HISTORY
  393.  *        01-Aug-89    Creation.
  394.  *
  395.  * BUGS
  396.  *
  397.  * SEE ALSO
  398.  *        RxilPostCancel(), RxilCheckCancel()
  399.  */
  400.  
  401. void RxilEndCancel( void )
  402. {
  403.     struct RxilCancelReq *creq;
  404.  
  405.  
  406.     if( global_rdef == NULL )
  407.     {
  408.         return;
  409.     }
  410.  
  411.     creq = global_rdef->CReq;
  412.  
  413.     if( creq == NULL )
  414.     {
  415.         return;
  416.     }
  417.  
  418.     EndRequest( &creq->req, creq->win );
  419.  
  420.     CloseWindow( creq->win ); 
  421.  
  422.     FreeMem( creq, sizeof(struct RxilCancelReq) );
  423.  
  424.     global_rdef->CReq = NULL;
  425. }
  426.  
  427.